<?php
/*老师模糊查询表格           根据id搜索*/
('Access-Control-Allow-Origin：*');
include("../config/mysql.php");
$searchText = $_REQUEST['searchText'];
$id = $_REQUEST['id'];
$scale = $_REQUEST['scale'];
$limit = $_REQUEST['limit'];
$page = $_REQUEST['page'];
$company_id = $_REQUEST['company_id'];

/*查询语句 一级管理员和二级管理员*/
if ($scale == 1 || $scale == 2) {
     /*$sql = "SELECT * FROM teachers where scale >= '%{$scale}%'and tname LIKE '%{$searchText}%'";*/
     // $sql = "SELECT * FROM teachers WHERE company_id = {$company_id} AND scale >= '" . $scale . "' AND tname LIKE '%{$searchText}%'";
     /* $sql = "SELECT * FROM teachers where scale >= '%{$searchText}%'";*/
     $sql = "SELECT t.id,t.username,t.userpwd,t.tname,t.tphone,t.yhc,t.idCard,t.scale,t.salary,t.company_id,c.companyName,c.id as c_id FROM teachers t INNER JOIN company c ON t.company_id = c.id WHERE t.company_id = {$company_id} AND t.scale >= '{$scale}' AND t.tname LIKE '%{$searchText}%'";
} else {
     // $sql = "SELECT * FROM teachers WHERE company_id = {$company_id} AND id ='" . $id . "'";
     $sql = "SELECT t.id,t.username,t.userpwd,t.tname,t.tphone,t.yhc,t.idCard,t.scale,t.salary,t.company_id,c.companyName,c.id as c_id FROM teachers t INNER JOIN company c ON t.company_id = c.id WHERE t.id = {$id}";
}

// if ($id == 3) {
//      $sql = "SELECT t.id,t.username,t.userpwd,t.tname,t.tphone,t.yhc,t.idCard,t.scale,t.salary,t.company_id,c.companyName,c.id as c_id FROM teachers t INNER JOIN company c ON t.company_id = c.id WHERE t.scale >= '{$scale}' AND t.tname LIKE '%{$searchText}%'";
// }

$sql .= ' order by id desc';
$Mysql = new Mysql();
$count = $Mysql->getResultNum($sql);
$start = ($page - 1) * $limit;
$sql .= " limit {$start},{$limit}";

/*查询表格参数一表明   参数二 查询语句*/
$arr = $Mysql->likeSelectLayui($sql);
/*返回出去*/
if (is_array($arr) == 1) {
     $res = [
          'code' => 0,
          'msg' => '查询成功',
          'count' => $count,
          'data' => $arr
     ];
} else {
     $res = [
          'msg' => '没有查到数据',
     ];
}
echo json_encode($res, JSON_UNESCAPED_UNICODE);
/*关闭连接*/
$Mysql->close();
